{include file="public/head"}
<style>
    .m-cell {
        background-color: #FFF;
        position: relative;
        z-index: 1;
        margin-bottom: .35rem;
        height: 3rem;
        line-height: 3rem;
    }
</style>
<body style="background:#eee">

<header class="aui-header-default aui-header-fixed aui-header-bg">
    <a href="javascript:history.back(-1)" class="aui-header-item">
        <i class="aui-icon aui-icon-back-white"></i>
    </a>
    <div class="aui-header-center aui-header-center-clear">
        <div class="aui-header-center-logo">
            <div class="aui-car-white-Typeface" style="color:black;font-weight: bold;">新建地址</div>
        </div>
    </div>
    <a href="#" class="aui-header-item-icon"   style="min-width:0">
        <!--<i class="aui-icon aui-icon-search"></i>-->
    </a>
</header>


<section class="aui-myOrder-content">
    <div class="aui-prompt"><i class="aui-icon aui-prompt-sm"></i>填写您的地址信息</div>
    <div class="aui-Address-box">
        <p>
            <input class="aui-Address-box-input" type="text" id="name" placeholder="收件人姓名">
        </p>
        <p>
            <input class="aui-Address-box-input" type="text" id="phone" placeholder="手机号码">
        </p>
        <p>
            <input class="aui-Address-box-input" type="text" readonly id="J_Address"  placeholder="所在地区">
        </p>
        <p>
            <textarea class="aui-Address-box-text" id="address" placeholder="街道， 小区门牌等详细地址" rows="3"></textarea>
        </p>

    </div>
    <div class="aui-out">
        <a href="javascript:" class="red-color" style="color:#fff" id="add">保存并使用</a>
    </div>
</section>


<script type="text/javascript" src="__STATIC__/User/js/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/User/js/aui.js"></script>
<script type="text/javascript" src="__STATIC__/User/js/city.js"></script>
<script>
    /**
     * 默认调用
     */
    !function () {
        var $target = $('#J_Address');

        $target.citySelect();

        $target.on('click', function (event) {
            event.stopPropagation();
            $target.citySelect('open');
        });

        $target.on('done.ydui.cityselect', function (ret) {
            $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
        });
    }();
    /**
     * 设置默认值
     */
    !function () {
        var $target = $('#J_Address2');

        $target.citySelect({
            provance: '新疆',
            city: '乌鲁木齐市',
            area: '天山区'
        });

        $target.on('click', function (event) {
            event.stopPropagation();
            $target.citySelect('open');
        });

        $target.on('done.ydui.cityselect', function (ret) {
            $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
        });
    }();
    
    $('#add').on('click',function () {
        var name = $('#name').val();
        var phone = $('#phone').val();
        var area = $('#J_Address').val();
        var address = $('#address').val();

        if(name == ""){
            alert('请输入收件人姓名！');
            return false;
        }

        if(phone == ""){
            alert('请输入收件人电话！');
            return false;
        }

        if(phone.length != 11){
            alert('手机号码格式错误');
            return false;
        }

        if(area == ""){
            alert('请选择所在地区！');
            return false;
        }

        if(address == ""){
            alert('请输入详细地址！');
            return false;
        }

        $.ajax({
            type:"POST",
            url:"{:url('User/AddressAdd')}",
            data:{
                name:name,
                phone:phone,
                area:area,
                address:address
            },
            dataType:"json",
            success:function(data){
                alert(data.message);
                if(data.status == 1){
                    if("{$goods_id}"){
                        window.location.href="{:url('order/orderfound',['goods_id'=>$goods_id])}";
                    }else{
                        window.location.href="{:url('user/addresslist')}";
                    }
                    // window.location.href="{:url('order/orderfound',['goods_id'=>$goods_id])}";
                    // history.back(-2);
                }
            }
        })
    })
</script>

</body>
</html>